<?php
class M_statistik extends CI_Model{

	function pengunjung(){
            $sql = "select DAY(pengunjung_waktu) tanggal, count(pengunjung_id) pengunjung from t_pengunjung
where MONTH(pengunjung_waktu) = MONTH(NOW()) AND YEAR(pengunjung_waktu) = YEAR(NOW()) 
group by DAY(pengunjung_waktu)";
            $query = $this->db->query($sql);
            $result = $query->result();
            $data = array();
            foreach( $result  as $row){
                $data[$row->tanggal] = $row->pengunjung;
            }
        
            $last_day = date("t");
            $return = array();
            for($i=1; $i<= $last_day; $i++){
                $return[] = array($i, @$data[$i]);
            }
            return $return;
    }
    
    
	function userloket(){
            $sql = "select user_fullname, s_users_id, count(*) jumlah from t_pengunjung
left join s_users
on s_users_id = user_id
where s_users_id is not null
group by s_users_id";
            $query = $this->db->query($sql);
            $result = $query->result();
            $data = array();
            foreach( $result  as $row){
                $data[] = array(
                    "label" => $row->user_fullname,
                    "data" => $row->jumlah
                );
            }
        
            return $data;
    }
}
